home *** CD-ROM | disk | FTP | other *** search
/ Suzy B Software 2 / Suzy B Software CD-ROM 2 (1994).iso / new_file / mintprgs / mint112s / mint112s.lzh / mem.h < prev    next >
Encoding:
C/C++ Source or Header  |  1994-08-30  |  6.4 KB  |  210 lines

  1. /*
  2. Copyright 1990,1991,1992 Eric R. Smith.
  3. Copyright 1992,1993,1994 Atari Corporation.
  4. All rights reserved.
  5. */
  6.  
  7. #ifndef _mem_h
  8. #define _mem_h
  9.  
  10. #include "file.h"
  11.  
  12. typedef struct memregion {
  13.     long    loc;        /* base of memory region */
  14.     ulong    len;        /* length of memory region */
  15.     ushort    links;        /* number of users of region */
  16.     ushort    mflags;        /* e.g. which map this came from */
  17.     struct memregion *next; /* next region in memory map */
  18. } MEMREGION;
  19.  
  20. /* flags for memory regions: these are used only in MEMREGION struct */
  21. #define M_CORE        0x01    /* region came from core map */
  22. #define M_ALT        0x02    /* region came from alt map */
  23. #define M_SWAP        0x04    /* region came from swap map */
  24. #define M_KER        0x08    /* region came from kernel map */
  25. #define M_MAP        0x0f    /* and with this to pick out map */
  26.  
  27. #define M_SHTEXT    0x10    /* region is a shared text region */
  28. #define M_SHTEXT_T    0x20    /* `sticky bit' for shared text regions */
  29. #define M_FSAVED    0x40    /* region is saved memory of a forked process */
  30. #define M_KEEP        0x0100    /* don't free on process termination */
  31. #define M_SEEN        0x8000    /* for memused() to find links */
  32.  
  33. /* dummy type for virtual addresses */
  34. typedef struct vaddr {
  35.     char dummy;
  36. } *virtaddr;
  37.  
  38. /* structure for shared text regions */
  39.  
  40. typedef struct shtextreg {
  41.     FILEPTR *f;        /* what file did this come from? */
  42.     MEMREGION *text;    /* pointer to shared text region */
  43.     short mtime, mdate;    /* date & time for file */
  44.     struct shtextreg *next;
  45. } SHTEXT;
  46.  
  47. /*
  48.  * Here's the deal with memory bits:
  49.  *
  50.  * Mxalloc(long size, int mode) takes these fields in 'mode': BITS 0-2 hold
  51.  * values 0-3 for the old GEMDOS mode argument.  If bit 3 is on, then only
  52.  * F_PROTMODE (bits 4-7) counts, and it encodes the desired protection mode
  53.  * to change a block to. Else F_PROTMODE is the desired protection mode for
  54.  * the new block you're allocating.  In either case, F_PROTMODE turns into
  55.  * a PROT_* thusly: if it's zero, you get the F_PROTMODE value from curproc's
  56.  * prgflags. Else you get (F_PROTMODE >> F_PROTSHIFT)-1.
  57.  *
  58.  * The 0x4000 bit is carried along into get_region (but not from there into
  59.  * mark_region) and, if set, causes M_KEEP to be set in the region's
  60.  * mflags.
  61.  */
  62.  
  63. /* structure of exectuable program headers */
  64. typedef struct fileheader {
  65.     short    fmagic;
  66.     long    ftext;
  67.     long    fdata;
  68.     long    fbss;
  69.     long    fsym;
  70.     long    reserved;
  71.     long    flag;
  72.     short    reloc;
  73. } FILEHEAD;
  74.  
  75. #define GEMDOS_MAGIC 0x601a
  76.  
  77. /* flags for curproc->memflags */
  78. /* also used for program headers PRGFLAGS */
  79. #define F_FASTLOAD    0x01        /* don't zero heap */
  80. #define F_ALTLOAD    0x02        /* OK to load in alternate ram */
  81. #define F_ALTALLOC    0x04        /* OK to malloc from alt. ram */
  82. #define F_RESERVED    0x08        /* reserved for future use */
  83. #define F_MEMFLAGS    0xf0        /* reserved for future use */
  84. #define F_SHTEXT    0x800        /* program's text may be shared */
  85.  
  86. #define F_MINALT    0xf0000000L    /* used to decide which type of RAM to load in */
  87.  
  88. /* Bit in Mxalloc's arg for "don't auto-free this memory" */
  89. #define F_KEEP        0x4000
  90.  
  91. #define F_OS_SPECIAL    0x8000        /* mark as a special process */
  92.  
  93. /* flags for curproc->memflags (that is, PRGFLAGS) and also Mxalloc mode.  */
  94. /* (Actually, when users call Mxalloc, they add 0x10 to what you see here) */
  95. #define    F_PROTMODE    0xf0        /* protection mode bits */
  96. #define F_PROT_P    0x00        /* no read or write */
  97. #define F_PROT_G    0x10        /* any access OK */
  98. #define F_PROT_S    0x20        /* any super access OK */
  99. #define F_PROT_PR    0x30        /* any read OK, no write */
  100. #define F_PROT_I    0x40        /* invalid page */
  101.  
  102. /* actual values found in page_mode_table and used as args to alloc_region */
  103. #define PROT_P    0
  104. #define PROT_G    1
  105. #define PROT_S    2
  106. #define PROT_PR    3
  107. #define PROT_I    4
  108. #define PROT_MAX_MODE 4
  109. #define PROT_PROTMODE 0xf   /* these bits are the prot mode */
  110. #define PROT_NOCHANGE -1
  111.  
  112. #define F_PROTSHIFT    4
  113.  
  114. typedef MEMREGION **MMAP;
  115.  
  116. #ifndef GENMAGIC
  117. extern MMAP core, alt, ker, swap;
  118. #endif
  119.  
  120. /* compilers differ on what "sizeof" returns */
  121. #define SIZEOF        (long)sizeof
  122.  
  123. /* QUANTUM: the page size for the mmu: 8K.  This is hard-coded elsewhere. */
  124. #define QUANTUM 0x2000L
  125.  
  126. /* MiNT leaves this much memory for TOS to use (8K)
  127.  */
  128. #define TOS_MEM        (QUANTUM)
  129.  
  130. /* MiNT tries to keep this much memory available for the kernel and other
  131.  * programs when a program is launched (8K)
  132.  */
  133. #define KEEP_MEM    (QUANTUM)
  134.  
  135. /*
  136.  * how much memory should be allocated to the kernel? (24K)
  137.  */
  138. #define KERNEL_MEM    (3*QUANTUM)
  139.  
  140. /* macro for rounding off region sizes to QUANTUM (page) boundaries */
  141. /* there is code in mem.c that assumes it's OK to put the screen
  142.  * in any region, so this should be at least 256 for STs (16 is OK for
  143.  * STes, TTs, and Falcons). We actually set a variable in main.c
  144.  * that holds the screen boundary stuff.
  145.  */
  146. extern int no_mem_prot;
  147. extern int screen_boundary;
  148.  
  149. #define MASKBITS    (no_mem_prot ? screen_boundary : (QUANTUM-1))
  150. #define ROUND(size) ((size + MASKBITS) & ~MASKBITS)
  151.  
  152. /* interesting memory constants */
  153.  
  154. #define EIGHT_K (0x400L*8L)
  155. #define ONE_MEG 0x00100000L
  156. #define LOG2_ONE_MEG 20
  157. #define LOG2_16_MEG 24
  158. #define LOG2_EIGHT_K 13
  159. #define SIXTEEN_MEG (0x400L*0x400L*16L)
  160.  
  161. /* macro for turning a curproc->base_table pointer into a 16-byte boundary */
  162. #define ROUND16(ld) ((long_desc *)(((ulong)(ld) + 15) & ~15))
  163.  
  164. /* TBL_SIZE is the size in entries of the A, B, and C level tables */
  165. #define TBL_SIZE (16)
  166. #define TBL_SIZE_BYTES (TBL_SIZE * sizeof(long_desc))
  167.  
  168. typedef struct {
  169.     short limit;
  170.     unsigned zeros:14;
  171.     unsigned dt:2;
  172.     struct long_desc *tbl_address;
  173. } crp_reg;
  174.  
  175. /* format of long descriptors, both page descriptors and table descriptors */
  176.  
  177. typedef struct {
  178.     unsigned limit;        /* set to $7fff to disable */
  179.     unsigned unused1:6;
  180.     unsigned unused2:1;
  181.     unsigned s:1;        /* 1 grants supervisor access only */
  182.     unsigned unused3:1;
  183.     unsigned ci:1;        /* cache inhibit: used in page desc only */
  184.     unsigned unused4:1;
  185.     unsigned m:1;        /* modified: used in page desc only */
  186.     unsigned u:1;        /* accessed */
  187.     unsigned wp:1;        /* write-protected */
  188.     unsigned dt:2;        /* type */
  189. } page_type;
  190.  
  191. typedef struct long_desc {
  192.     page_type page_type;
  193.     struct long_desc *tbl_address;
  194. } long_desc;
  195.  
  196. typedef struct {
  197.     unsigned enable:1;
  198.     unsigned zeros:5;
  199.     unsigned sre:1;
  200.     unsigned fcl:1;
  201.     unsigned ps:4;
  202.     unsigned is:4;
  203.     unsigned tia:4;
  204.     unsigned tib:4;
  205.     unsigned tic:4;
  206.     unsigned tid:4;
  207. } tc_reg;
  208.  
  209. #endif /* _mem_h */
  210.